//
//  CCStatusCellBottomView.swift
//  CC-SinaWeibo
//
//  Created by Chenchen on 16/2/21.
//  Copyright © 2016年 Chenchen. All rights reserved.
//

import UIKit
import SnapKit

class CCStatusCellBottomView: UIView
{
    
// MARK: 用户点击事件
    @objc private func repostBtnDidClick()
    {  // 测试控制器
        let temp = CCTempViewController()
        // 跳转视图控制器
        navViewController()?.pushViewController(temp, animated: true)
    }
    
    
    // MARK:重写构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(white: 0.8, alpha: 1)
        setupUI()
    }
    
    //默认实现报错
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: 设置界面
    private func setupUI() {
        addSubview(repostBtn)  // 转发按钮
        addSubview(commentBtn) // 评论按钮
        addSubview(oYeahBtn)  // 点赞按钮
        
        //设置约束
        // 转发按钮
        repostBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
        }
        // 评论按钮
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(repostBtn.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            make.width.equalTo(repostBtn.snp_width)
        }
        // 点赞按钮
        oYeahBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            //三等分
            make.right.equalTo(self.snp_right)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        let sepView1 = sepView()
        let sepView2 = sepView()
        
        // 添加 "|" 条
        addSubview(sepView1)
        addSubview(sepView2)
        
        //设置约束
        sepView1.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(repostBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(0.5)
        }
        // 公式:view1.attr1 = view2.attr2 * multiplier + constant
        sepView2.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(0.5)
        }
        
        // 添加点击事件
        repostBtn.addTarget(self, action: "repostBtnDidClick", forControlEvents: .TouchUpInside)
        
    }
    
    
    
    private func sepView() -> UIView {
        let v = UIView()
        v.backgroundColor = UIColor.blackColor()
        return v
    }
    
    //懒加载视图
    //转发按钮
    private lazy var repostBtn: UIButton = UIButton(backImageName: nil, title: "转发", textColor: UIColor.lightGrayColor(),imageName: "timeline_icon_retweet")
    //评论按钮
    private lazy var commentBtn: UIButton = UIButton(backImageName: nil, title: "评论", textColor: UIColor.lightGrayColor(),imageName: "timeline_icon_comment")
    //点赞的按钮
    private lazy var oYeahBtn: UIButton = UIButton(backImageName: nil, title: "赞", textColor: UIColor.lightGrayColor(),imageName: "timeline_icon_unlike")
}

